﻿
using WebAssistant.BusinessLogic;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Assistant.Forms.Configuration
{
    public partial class FormChangeLockScreenPassword : UIEditForm
    {
        public FormChangeLockScreenPassword()
        {
            InitializeComponent();
        }


        private void FormChangeLockScreenPassword_ButtonOkClick(object sender, EventArgs e)
        {
            string old_password = tb_OldPassword.Text;
            string new_password = tb_NewPassword.Text;
            string confirm_password = tb_ConfirmPassword.Text;

            if (old_password == "")
            {
                ShowErrorTip("请输入旧密码！");
                return;
            }
            else
            {
                if (old_password != DataAccess.GetSettingByKey("assistant.password"))
                {
                    ShowErrorTip("旧密码输入错误！");
                    return;
                }
            }            

            if (new_password == confirm_password)
            {
                try
                {
                    var result = DataAccess.UpdateSettingByKey("assistant.password", tb_NewPassword.Text.Trim());
                    if (result == 1)
                    {
                        ShowSuccessTip("锁屏密码更改成功！");

                    }
                    else
                    {
                        ShowErrorTip("锁屏密码更改失败！");
                    }
                    Close();
                }
                catch (Exception ex)
                {
                    ShowErrorDialog("错误："+ ex.ToString());
                }
            }
            else
            {
                ShowErrorTip("输入的新密码不一致！");
            }
        }

        private void FormChangeLockScreenPassword_ButtonCancelClick(object sender, EventArgs e)
        {
            Close();
        }
    }
}
